<template>
    <view class="content">
        <view class="bg"></view>
        
        <view class="box">
            <view class="item">
                <view>公司名称</view>
                <input type="text" v-model="name" placeholder="请输入" class="inp" :disabled="disabled">
            </view>
            <view class="item">
                <view>营业执照</view>
                <image :src="pic_url || '../../static/image/g_up.png'" class="up" @click="chooseImage"></image>
            </view>
            <!-- <view class="item">
                <view>联系电话</view>
                <input type="number" v-model="tel" placeholder="请输入" class="inp">
            </view> -->
        </view>
        
        <view class="btn" @click="doSubmit">确认提交</view>
    </view>
</template>

<script>
    export default {
        data() {
            return {
                name: '',
                pic: '',
                pic_url: '',
                id: '',
            };
        },
        onLoad(option) {
            if (option.id) {
                this.id = option.id
                this.getData()
            }
        },
        methods: {
            doSubmit(){
                if (!this.name) {
                    this.$toast('请输入公司名称')
                    return
                }
                if (!this.pic) {
                    this.$toast('请上传营业执照')
                    return
                }
            	this.$ajax('add_member_auth', {
            		userToken: this.$getSync('userToken'),
                    id: this.id,//认证信息id 没有不填
                    corporate_name: this.name,//公司名称
                    business_license: this.pic,//营业执照
            	}).then(ret => {
            		if (ret.status == 0) {
                        this.$toast('提交成功')
                        setTimeout(() => {
                            this.$backT()
                        }, 500)
            		} else {
            			this.$toast(ret.message);
            		}
            	});
            },
            
            getData(){
            	this.$ajax('member_auth', {
            		userToken: this.$getSync('userToken'),
            	}).then(ret => {
            		if (ret.status == 0) {
                        this.name = ret.data.corporate_name
                        this.pic = ret.data.business_license
                        this.pic_url = ret.data.business_license_uri
            		} else {
            			this.$toast(ret.message);
            		}
            	});
            },
            
            chooseImage() {
                uni.chooseImage({
                    count: 1, //默认9
                    sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图，默认二者都有
                    sourceType: ['album', 'camera'], // 相机拍照 album 相册、camera 拍照
                    success: (res) => {
                        this.$upLoadPic(res.tempFilePaths[0]).then(ret => {
                            console.log(ret)
                            this.pic = ret.data.id
                            this.pic_url = ret.data.attach_uri
                        });
                    }
                });
            },
            
        }
    };
</script>

<style lang="scss">
    page{
        background-color: #f5f5f5;
    }
    .content {
    	padding: 20rpx;
    }
    
    .bg {
    	width: 100%;
    	height: 390rpx;
    	position: absolute;
    	top: 0;
    	left: 0;
    	z-index: -1;
    	background: linear-gradient(to bottom, #00734c, #f5f5f5);
    }
    
    .top{
        padding: 50rpx;
        background-color: #fff;
        border-radius: 20rpx;
        margin-bottom: 20rpx;
    }
    .dsh{
        width: 305rpx;
        height: 250rpx;
        margin: 0 auto;
    }
    .shsb{
        width: 326rpx;
        height: 266rpx;
        margin: 0 auto;
    }
    .title{
        display: flex;
        justify-content: flex-start;
        align-items: center;
        font-size: 28rpx;
        font-weight: bold;
        padding-top: 35rpx;
        padding-bottom: 15rpx;
    }
    .tip{
        width: 34rpx;
        height: 35rpx;
        margin-right: 15rpx;
    }
    .text{
        font-size: 24rpx;
        color: #acacac;
    }
    
    .box{
        padding: 0 25rpx;
        background-color: #fff;
        border-radius: 20rpx;
    }
    .item{
        padding: 30rpx 0;
        display: flex;
        justify-content: space-between;
        align-items: center;
        border-bottom: 2rpx solid #f0f0f0;
    }
    .item:last-child{
        border-bottom: none;
    }
    .inp{
        flex: 1;
        text-align: right;
    }
    .up{
        width: 160rpx;
        height: 160rpx;
    }
    
    .btn{
        background-color: #00734c;
        padding: 25rpx;
        border-radius: 50rpx;
        font-size: 34rpx;
        color: #fff;
        text-align: center;
        margin-top: 40rpx;
    }

</style>
